import * as types from '../type';

const state = {
  // actionSheet显示与否
  actions: [],
  sheetVisible: false,
  pickerValue: '',
  picker: '',
  pickerym: '',
  pickern: '',
  pickerCallback: function () {},
  pickerymCallback: function () {},
  pickernCallback: function () {}
};
const actions = {
  /*actionSheet*/
  setSheetVisible ({commit}, data) {
    commit(types.SHEET_VISIBLE, data);
  },
  setSheetAction ({commit}, data) {
    commit(types.SHEET_ACTIONS, data);
    commit(types.SHEET_VISIBLE, true);
  },
  /*date picker*/
  setDatePiker ({commit}, data) {
    this.getters.picker.open();
    commit(types.DATE_PICKER, data);
  },
  setDatePickerym ({commit}, data) {
    commit(types.DATE_PICKERYM, data);
    this.getters.pickerym.open();
  },
  setDatePickern ({commit}, data) {
    commit(types.DATE_PICKERN, data);
    this.getters.pickern.open();
  },
  setPicker ({commit}, picker) {
    commit(types.SET_PICKER, picker);
  },
  setPickerym ({commit}, picker) {
    commit(types.SET_PICKERYM, picker);
  },
  closeDatePiker ({commit}) {
    if (this.getters.picker) {
      this.getters.picker.close();
    }
  },
  closePickerym ({commit}) {
    if (this.getters.pickerym) {
      this.getters.pickerym.close();
    }
  },
  closeDatePickern ({commit}) {
    if (this.getters.pickern) {
      this.getters.pickern.close();
    }
  },
  setPickern ({commit}, picker) {
    commit(types.SET_PICKERN, picker);
  }
};

const getters = {
  sheetVisible: state => state.sheetVisible,
  actions: state => state.actions,
  pickerValue: state => state.pickerValue,
  picker: state => state.picker,
  pickerym: state => state.pickerym,
  pickern: state => state.pickern,
  pickerCallback: state => state.pickerCallback,
  pickerymCallback: state => state.pickerymCallback,
  pickernCallback: state => state.pickernCallback
};

const mutations = {
  [types.SHEET_VISIBLE] (state, res) {
    state.sheetVisible = res;
  },
  [types.SHEET_ACTIONS] (state, res) {
    state.actions = res;
  },
  [types.DATE_PICKER] (state, res) {
    state.pickerValue = res.value;
    state.pickerCallback = res.method;
  },
  [types.DATE_PICKERYM] (state, res) {
    state.pickerymValue = res.value;
    state.pickerymCallback = res.method;
  },
  [types.DATE_PICKERN] (state, res) {
    state.pickernValue = res.value;
    state.pickernCallback = res.method;
  },
  [types.SET_PICKER] (state, picker) {
    state.picker = picker;
  },
  [types.SET_PICKERYM] (state, picker) {
    state.pickerym = picker;
  },
  [types.SET_PICKERN] (state, picker) {
    state.pickern = picker;
  }

};

export default {
  state,
  actions,
  getters,
  mutations
};
